#include <dlfcn.h>
#include <errno.h>
#include <stdlib.h>
#include <memory.h>
#ifdef USE_HBM
#include <memkind.h>
#endif

bool kpex_use_hbm() {
#ifdef USE_HBM
    return true;
#else
    return false;
#endif
}

int kpex_posix_memalign(void **memptr, size_t alignment, size_t size)
{
#ifdef USE_HBM
    return memkind_posix_memalign(MEMKIND_HBW_HUGETLB, memptr, alignment, size);
#else
    return posix_memalign(memptr, alignment, size);
#endif
}

void kpex_free(void *ptr)
{
#ifdef USE_HBM
    memkind_free(MEMKIND_HBW_HUGETLB, ptr);
#else
    return free(ptr);
#endif
}
